package com.gugee.ins.common.dal.mapper.blogger;

import com.gugee.ins.common.model.ai.InComeResponse;
import com.gugee.ins.common.model.ai.InsBloggerCategory;
import com.gugee.ins.common.model.ai.InsBloggerLanguage;
import com.gugee.ins.common.model.mysql.blogger.InsBloggerMain;
import com.gugee.ins.common.model.spider.blogger.InsBloggerUserFromId;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


public interface InsBloggerMainExtMapper extends InsBloggerMainMapper {

    @Select("<script>" +
            " SELECT uid,username,full_name,biography,pic_url,external_url,following_count,follower_count, " +
            "(select b.id from ins_dic_follower_size b where a.follower_count between size_start and size_end) follower_size  " +
            ",media_count,igtv_count,following_tag_count,usertags_count,is_private,is_verified,is_business,is_zombie,is_massive_following,account_type  " +
            ",category_name,business_category_name,overall_category_name,fbid,contact_phone_number,public_email,public_phone_country_code,public_phone_number,city_id,city_name,#{createTime} create_time  " +
            "FROM ins_blogger a WHERE a.uid  IN " +
            "<foreach item='uid' index='index' collection='uidS'  open='(' separator=',' close=')'>" +
            "#{uid}" +
            "</foreach>" +
            " AND follower_count>= #{followerCount} AND NOT EXISTS (select 1 from ins_blogger_main b where b.uid =a.uid )" +
            "</script>")
    List<InsBloggerMain> produceInsBloggerMainsFromBlogger(List<Long> uidS, int followerCount,long createTime);

    int updateByPrimaryKeySelective(InsBloggerUserFromId insBloggerUserFromId);

    /**
     * 根据uid 更新年龄和性别
     * @param age
     * @param gender
     * @param birth
     * @param race
     * @param uid
     */
    void updateAiGenderAndAiAgeByUid(@Param("age")int age, @Param("gender")int gender, @Param("birth")int birth,
                                     @Param("race")String race, @Param("uid")long uid);

    /**
     * 根据uid 更新国家
     * @param uid
     * @param nation
     * @param nationSource
     */
    void updateNation(@Param("uid")long uid,@Param("nation")String nation,@Param("nationSource")int nationSource);

    /**
     * 根据uid 更新语言
     * @param uid
     * @param language
     */
    void updateLanguage(@Param("uid")long uid,@Param("language")String language);

    /**
     * 批量更新 语言
     * @param insBloggerLanguages
     */
    void batchUpdateLanguage(@Param("insBloggerLanguages") List<InsBloggerLanguage> insBloggerLanguages);

    /**
     * 根据uids 更新 近30天粉丝增长数和粉丝增长率
     * @param uids
     * @param today
     */
    void updateLastFollowerGrowByUids(@Param("uids")List<Long> uids,int today);

    /**
     * 根据id分页查询uid
     * @param startId
     * @param endId
     * @param followerCount
     * @return
     */
    @Select("select uid from ins_blogger_main where id between #{startId} and #{endId} " +
            " and follower_count >= #{followerCount} and account_status = 0 ")
    List<Long> findInsBloggerUidByPages(@Param("startId")long startId,@Param("endId") long endId,@Param("followerCount") long followerCount);

    /**
     * 更新帖子采集时间
     * @param uid
     * @param updateTime
     */
    void updateMediaCollectTime(@Param("uid")long uid,@Param("updateTime")long updateTime);

    /**
     * 更新帖子平均参与率
     * @param uid
     * @param timeRang
     */
    void updateAvgEr(@Param("uid")long uid,@Param("timeRang")long timeRang);

    /**
     * 更新评论采集
     * @param uid
     * @param commentCollectCount
     * @param updateTime
     */
    void updateCommentCollectTime(@Param("uid")long uid,@Param("commentCollectCount") int commentCollectCount,@Param("updateTime")long updateTime);

    /**
     * 更新粉丝列表采集时间
     * @param uid
     * @param updateTime
     */
    void updateFollowerCollectTime(@Param("uid")long uid,@Param("updateTime")long updateTime);

    /**
     * 更新博主广告帖子平均ER值
     * @param uid
     * @param brandMediaEr
     */
    void updateBrandMediaEr(@Param("uid")long uid,@Param("brandMediaEr")double brandMediaEr);

    /**
     * 更新真实粉丝占比率
     * @param id
     * @param realFollowerRate
     * @param nowTime
     */
    void updateRealFollowerRate(@Param("id")long id,@Param("realFollowerRate")double realFollowerRate,
                                @Param("nowTime")long nowTime);

    /**
     * 批量更新ai收入
     * @param inComeResponses
     */
    void batchUpdateIncome(@Param("inComeResponses")List<InComeResponse> inComeResponses);

    /**
     * 更新活跃粉丝的统计时间字段
     * @param insBloggerMain
     */
    void updateStActiveFollowerTime(@Param("insBloggerMain")InsBloggerMain insBloggerMain);

    /**
     * 更新播主平均点赞数和平均评论数
     * @param uid
     * @param limitTime
     */
    void updateMediaAvg(@Param("uid")long uid,@Param("limitTime") long limitTime);

    /**
     * 批量更新ai分类
     * @param insBloggerCategories
     * @param updateTime
     */
    void batchUpdateAiCategory(@Param("insBloggerCategories")List<InsBloggerCategory> insBloggerCategories,@Param("updateTime")long updateTime);

    /**
     * 更新最近分析播主分类的时间
     * @param uid
     * @param updateTime
     */
    void updateLastAnalysisCategoryTime(@Param("uid")long uid,@Param("updateTime") long updateTime);

    /**
     * 更新状态
     * @param uid
     * @param status
     */
    void updateAccountStatus(@Param("uid")long uid ,@Param("status")int status);

    /**
     * 更新最近分析品牌的标记字段
     * @param uid
     * @param brandJson
     * @param nowTime
     */
    void updateAiBrand(@Param("uid")long uid ,@Param("brandJson")String brandJson ,@Param("nowTime")long nowTime);
}